package com.groupbuying.payproducer.controller;

import com.groupbuying.payproducer.domain.PayInfoDO;
import com.groupbuying.payproducer.service.PayInfoService;
import com.groupbuying.payproducer.service.PayOrderService;
import com.groupbuying.payproducer.utils.PageUtils;
import com.groupbuying.payproducer.utils.Query;
import com.groupbuying.payproducer.utils.apiresult.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单支付主记录
 *
 * @author zmlmagic
 * @email zmlmagic@163.com
 * @date 2019-05-10 02:12:56
 */

@RestController
@RequestMapping()
public class PayInfoController {

    @Autowired
    private PayInfoService payInfoService;

    @Autowired
    private PayOrderService payOrderService;

    /**
     * @api {get} /list 查询支付信息
     * @apiDescription 分页查询支付信息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} params 参数描述详情：{id:订单id,isDelete:删除标志,gmtCreate:创建时间,gmtModified:更新时间,payState:支付状态,payType:支付类型,payChannel:支付通道,payMoney:支付金额,payCur:支付积分,payBalance:支付余额,sort:排序字段,order:排序方式,offset:页数,limit:条数}
     * @apiSuccess {JSON} pageUtils 成功返回结果:{id:支付单id,is_delete:删除标志,gmt_create:创建时间,gmt_modified:修改时间,pay_state:支付状态,pay_type:支付类型,pay_channel:支付通道,pay_money:支付余额,pay_cur:支付积分,pay_balance:支付余额,total:总条数}
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * @tar
     */
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);
        List<PayInfoDO> payInfoList = payInfoService.list(query);
        int total = payInfoService.count(query);
        PageUtils pageUtils = new PageUtils(payInfoList, total);
        return pageUtils;
    }


    /**
     * @api {post} /createWXPayInfo 微信支付
     * @apiDescription 创建预支付单,获取预支付信息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {JSON} params 参数描述详情：{payMoney:支付金额,orderId:订单id,code:code,formId:formId,counterId:商户id}
     * @apiSuccess {JSON} ApiResult 成功返回结果:{appId:服务商的APPID,timeStamp:获取code时间：商户号,nonceStr:随机字符串,package:,signType:sign_type,paySign:签名,payId:支付单id}
     * @apiError {class} ApiResult 错误信息 code,错误提示
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar
     */
    @PostMapping("/createWXPayInfo")
    public ApiResult createWXPayInfo(@RequestParam Map<String, Object> params) {
        return payOrderService.createWXPayInfo(params);
    }


    /**
     * @api {post} /createCurrencyPayInfo 积分支付
     * @apiDescription 创建预支付单,获取预支付信息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} params 参数描述详情：{payCurrency:支付积分,orderId:,code:,formId:formId,counterId:商户id}
     * @apiSuccess {JSON} ApiResult 成功返回结果:{prePayNo:积分支付预支付单号,payMoney:支付金额,payId:支付单id}
     * @apiError {JSON} ApiResult 错误信息 code,错误提示
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar
     */
    @PostMapping("/createCurrencyPayInfo")
    public ApiResult createCurrencyPayInfo(@RequestParam Map<String, Object> params) {
        return payOrderService.createCurrencyPayInfo(params);
    }

    /**
     * @api {post} /createBalancePayInfo 余额支付
     * @apiDescription 创建预支付单,获取预支付信息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} params 参数描述详情：{payBalance:支付余额,orderId:,code:,formId:formId,counterId:商户id}
     * @apiSuccess {JSON} ApiResult 成功返回结果:{prePayCode:余额预支付单code,prePayNo:余额预支付单号,payMoney:支付金额,payId:支付单id}
     * @apiError {JSON} ApiResult 错误信息 code,错误提示
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar
     */
    @PostMapping("/createBalancePayInfo")
    public ApiResult createBalancePayInfo(@RequestParam Map<String, Object> params) {
        return payOrderService.createBalancePayInfo(params);
    }

    /**
     * @api {post} /createAliPayInfo 支付宝支付
     * @apiDescription 创建预支付单,获取预支付信息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {Map} params 参数描述详情：{payMony:支付余额,orderId:,code:,formId:formId,counterId:商户id}
     * @apiSuccess {JSON} ApiResult 成功返回结果:{tradeNO:第三方id,payId:支付单id}
     * @apiError {JSON} ApiResult 错误信息 code,错误提示
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar
     */
    @PostMapping("/createAliPayInfo")
    public ApiResult createAliPayInfo(@RequestParam Map<String, String> params) {
        return payOrderService.createAliPayInfo(params);
    }

    /**
     * @api {get} /getPayInfoByOrderId 获取支付单信息
     * @apiDescription 用订单id获取支付单信息
     * @apiGroup pay
     * @apiHeader {String} Authorization 用户授权token
     * @apiParam {String} orderId 订单id
     * @apiSuccess {JSON} Map 成功返回结果:{id:支付单id,is_delete:删除标志,gmt_create:创建时间,gmt_modified:修改时间,pay_state:支付状态,pay_type:支付类型,pay_channel:支付通道,pay_money:支付余额,pay_cur:支付积分,pay_balance:支付余额,outTradeNo:第三方id}
     * @apiVersion 1.0.0
     * @apiExample
     * author srlg
     * date 2019-10-25
     * tar
     */
    @GetMapping("/getPayInfoByOrderId")
    public Map<String, String> getPayInfoByOrderId(String orderId) {
        return payInfoService.getPayInfoByOrderId(orderId);
    }
}
